﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RGiesecke.DllExport;
using System.Collections;
using System.ComponentModel;
using System.IO;
using System.Reflection;
using System.Runtime.Serialization.Json;

namespace CQ.CSharpSDK.Interface
{
    public class LoadDLL
    {
        object tempobject;
        public string classname;
        public string DllName { get; set; }
        public string DLLPath { get; set; }
        public string PlugsPath { get; set; }
        public LoadDLL()
        {
            string[] files = Directory.GetFiles("plug");
            //if(File.Exists(Path.GetFileNameWithoutExtension(DLLPath)))
            foreach (string file in files)
            {
                if (file.ToUpper().EndsWith(".DLL"))
                {
                    DLLPath = Assembly.GetExecutingAssembly().Location;
                    DllName = DLLPath.Split('\\').Last<string>();
                    Assembly ab = Assembly.LoadFrom(file);
                    Type[] types = ab.GetTypes();
                    foreach (Type t in types)
                    {
                        Console.WriteLine("!!");
                        Console.WriteLine(Path.GetFileNameWithoutExtension(DLLPath));
                        classname = t.FullName;
                        tempobject = ab.CreateInstance(t.FullName);

                    }
                }
            }
        }
        public void Execute(string name)
        {

        }
    }
}
